<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    class Student {
        static instance = null

        constructor(value) {
            this.name = value;
        }

        static getInstance(value) {
            // 单例不存在 or 存在的单例不是指向其构造函数
            if (!Student.instance || !(Student.instance instanceof Student)) {
                Student.instance = new Student(value);
            }
            return Student.instance;
        }
    }

    let a = Student.getInstance("localStorage");
    let b = Student.getInstance("localStorage");
    console.log(a === b);
</script>
</body>
</html>
